﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Security.Cryptography;
using System.Text.RegularExpressions;

namespace ReadManga
{
    public class Utils
    {
        public static bool IsNextProcessing(long dwWaitTime, long dwStartTime)
        {
            long dwCurrentTime = System.Environment.TickCount;

            long dwDistance = dwCurrentTime - dwStartTime;

            if (dwStartTime == 0 || dwDistance >= dwWaitTime)
            {
                dwStartTime = dwCurrentTime;
                return true;
            }
            return false;
        }

        public static string GetStringBetweenText(string strInputString, string strStart, string strEnd)
        {
            String szMid = "";
            int iPos1 = strStart == "" ? 0 : strInputString.IndexOf(strStart);
            if (iPos1 >= 0)
            {
                iPos1 += strStart.Length;
                int iPos2 = strEnd == "" ? strInputString.Length : strInputString.IndexOf(strEnd, iPos1);
                if (iPos2 >= iPos1)
                {
                    szMid = strInputString.Substring(iPos1, iPos2 - iPos1);
                }
            }
            return szMid;
        }
        public static string strip_tags(string htmlText)
        {
            return Regex.Replace(htmlText, "<[^>]*>", "", RegexOptions.Singleline);
        }

        public static string strip_tags(string htmlInput, string htmltagUse)//sample: user tag img,a => htmltagUse="img|/img|a|/a"
        {
            return Regex.Replace(htmlInput, "<(?!" + htmltagUse + ")[^>]*>", " ", RegexOptions.Compiled);
        }
    }
}
